package cardwall.client.view;

import cardwall.shared.Task;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;

/**
 * @author $LastChangedBy: vogensen $
 * @version $Revision: 2 $
 */
public class HeaderPanel extends HorizontalPanel {
    private Button newButton;
    private Button editButton;
    private Task selectedTask;

    public void init() {
        setWidth("100%");
        HorizontalPanel buttonPanel = new HorizontalPanel();
        newButton = new Button("New");
        buttonPanel.add(newButton);
        editButton = new Button("Edit");
        editButton.setEnabled(false);
        buttonPanel.add(editButton);
        add(buttonPanel);

        Label titleLabel = new Label("Cardwall");
        add(titleLabel);
        setCellHorizontalAlignment(titleLabel, HorizontalPanel.ALIGN_RIGHT);
    }

    public void addNewButtonClickListener(ClickListener clickListener) {
        newButton.addClickListener(clickListener);
    }

    public void addEditButtonClickListener(ClickListener clickListener) {
        editButton.addClickListener(clickListener);
    }

    public void setSelectedTask(Task task) {
        this.selectedTask = task;
        editButton.setEnabled(task != null);
    }

    public Task getSelectedTask() {
        return selectedTask;
    }
}
